// hyb_yl/pharmacy/pages/scan_add/scan_add.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var j_id = options.j_id;
    var that = this;
    that.setData({
      j_id:j_id
    })
    wx.setNavigationBarTitle({
      title: '添加设备',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  saoma:function(e){
    var that = this;
    wx.scanCode({
      success:function(re){
        var sn = re.result;
        app.util.request({
          'url':"entry/wxapp/index.binding",
          data:{
            openid:wx.getStorageSync('openid'),
            sn:sn,
            type:e.currentTarget.dataset.type,
            j_id:that.data.j_id
          },
          success:function(res){
            var code = res.data.code;
            if(code == 1)
            {
              wx.showModal({
                title: '提示',
                content:res.data.message,
                showCancel:false,
                success:function(con){
                  if(con.confirm)
                  {
                    wx.navigateTo({
                      url: '/hyb_yl/pharmacy/pages/equipment/equipment',
                    })
                  }
                  
                }
              })
            }else if(code == 2)
            {
              app.util.request({
                'url':"entry/wxapp/index.changebundling",
                data:{
                  sn:sn,
                  openid:wx.getStorageSync('openid'),
                  j_id:that.data.j_id,
                  type:e.currentTarget.dataset.type,
                  j_id:that.data.j_id
                },
                success:function(res){
                  wx.navigateTo({
                    url: '/hyb_yl/pharmacy/pages/equipment/equipment',
                  })
                }
              })
            }else{
              wx.showModal({
                title: '提示',
                content:res.data.message,
                success:function(con){
                  if(con.confirm)
                  {
                    wx.navigateTo({
                      url: '/hyb_yl/pharmacy/pages/equipment/equipment',
                    })
                  }
                  
                }
              })
            }
            
          }
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})